package net.csdn.business.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author zhangyl
 * @date 2022/6/15 16:31
 */
@Getter
@AllArgsConstructor
public enum RoleEnum {

    /**
     * 角色枚举
     */
    MAINTAINER("maintainer", "管理者", ProjectEnum.AccessLevelEnum.MANAGER.getCode()),
    DEVELOPER("developer", "开发者", ProjectEnum.AccessLevelEnum.DEVELOPER.getCode()),
    GUESTER("guest", "浏览者", ProjectEnum.AccessLevelEnum.GUEST.getCode()),
    ;
    final String code;
    final String desc;

    /**
     * 对应的项目权限的code {@link ProjectEnum.AccessLevelEnum}
     */
    final int level;

    public static RoleEnum ofCode(String code) {
        for (RoleEnum role : RoleEnum.values()) {
            if (role.code.equals(code)) {
                return role;
            }
        }
        throw new IllegalArgumentException("RoleEnum param error");
    }

    public static RoleEnum ofLevel(int level) {
        for (RoleEnum role : RoleEnum.values()) {
            if (role.level==level) {
                return role;
            }
        }
        throw new IllegalArgumentException("RoleEnum param error");
    }
}